<template>
    <div class="resetPwd">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="原密码">
          <el-input type="password" v-model="form.password" show-password></el-input>
        </el-form-item>
        <el-form-item label="新密码">
          <el-input type="password" v-model="form.newPassword" show-password></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="reset">确认修改</el-button>
        </el-form-item>

      </el-form>
      <el-dialog
        title="温馨提示"
        :visible.sync="dialogVisible"
        width="30%">
        <span>原密码输入错误</span>
        <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false">确 认</el-button>
      </span>
      </el-dialog>
    </div>
</template>

<script>
    import {requestPost} from "../../../network/request";

    export default {
        name: "resetCode",
      data(){
          return {
            dialogVisible: false,
            isTrue: false,
            form: {
              name: '',
              password: '',
              newPassword: ''
            }
          }
      },
      mounted() {

      },
      methods:{
          reset(){

            requestPost({
              url: 'user/update',
              data:{
                password: this.form.password,
                newpassword: this.form.newPassword
              }
            }).then(res=>{
              console.log(res.data);
              this.isTrue = res.data;
              if(!this.isTrue){
                this.dialogVisible = true;
                return false;
              }else{
                alert("修改成功")
                this.$router.replace("/login");
              }
            })

          }
      }
    }
</script>

<style scoped>
  .resetPwd{
    text-align: center;
    margin: 0 auto;
    width: 50%;
    padding-top: 5%;
  }
</style>
